package com.huizhonglm.diap.ui.wallet;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.R;
import com.huizhonglm.diap.api.model.wallet.QueueInfo;

import java.util.List;

/**
 * 附近商品列表适配器
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-07 13:42
 */
public class QueryQueueAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<QueueInfo> data;

    private int mainRed;
    private int yahui;

    public QueryQueueAdapter(Context context, List<QueueInfo> data) {
        this.inflater = LayoutInflater.from(context);
        this.data = data;
        mainRed = context.getResources().getColor(R.color.mainRed);
        yahui = context.getResources().getColor(R.color.yahui);
    }

    public void setData(List<QueueInfo> data){
        this.data = data;
    }

    @Override
    public int getCount() {
        return EmptyUtil.isEmpty(data) ? 0 : data.size();
    }

    @Override
    public QueueInfo getItem(int position) {
        return EmptyUtil.isEmpty(data) ? null : data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.item_query_queue, parent, false);
            holder.ranking = (TextView) view.findViewById(R.id.ranking_txt);
            holder.amount = (TextView) view.findViewById(R.id.amount_txt);
            holder.status = (TextView) view.findViewById(R.id.status_txt);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        QueueInfo item = getItem(position);
        String status = item.getStatus();
        holder.amount.setText(item.getAmount() + "元");
        //1 是已返还  0是排队中
        if ("0".equals(status)) {
            holder.ranking.setTextColor(mainRed);
            holder.amount.setTextColor(mainRed);
            holder.status.setTextColor(mainRed);
            holder.ranking.setText("第" + item.getRanking() + "名");
            holder.status.setText("排队中");
        } else {
            holder.ranking.setTextColor(yahui);
            holder.amount.setTextColor(yahui);
            holder.status.setTextColor(yahui);
            holder.ranking.setText(item.getRanking() + "");
            holder.status.setText("已返现");
        }
        return view;
    }

    private class ViewHolder{
        private TextView ranking;
        private TextView amount;
        private TextView status;
    }
}
